<?php 
/*

入口文件 

*/
//header("Access-Control-Allow-Origin: *");
//header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
//header("Access-Control-Allow-Credentials: true");
$origin = isset($_SERVER['HTTP_ORIGIN'])? $_SERVER['HTTP_ORIGIN'] : '';
header('Access-Control-Allow-Origin:'.$origin);
header('Access-Control-Allow-Methods:POST, GET, OPTIONS, PUT, DELETE');
header('Access-Control-Allow-Headers:x-requested-with,content-type');
header("Access-Control-Allow-Credentials: true");
ini_set("display_errors","On");//开启错误显示
define('INDEX',true);

require_once 'Lib/Sing_core.php';


$mid = $_mid = $_GET['mid'];// = C::t('#weixin#user')->getMid($AppId);
if(empty($mid)) exit('Mid Error');
@include libfile('function/api');

//验证Mid正确性
$uid = C::t('#api#user')->getUid($mid);

//构造访问模块
if(!$_GET['m']) $_GET['m'] = 'index';
$do = 'api_'.$_GET['m'];
$d = $_GET['d'] = $_GET['d']?$_GET['d']:'index';

//初始化访客信息
inituser($mid);


$fun = new $do();
$data =  array();
$func = method_exists($fun, $d);
if ($func) {
    $dataTmp = $fun->$d();
    if($dataTmp){
        $data = $dataTmp; 
        unset($dataTmp);
    }
}

if(isset($data['Error']) && $func){
    if($_GET['callback']){
        echo 'var data = '.json_encode($data).';';
        echo $_GET['callback'].'(data);';
    }else{
        echo json_encode($data);
    }
}else{
    if($func){
        if($_G['inajax']) echo json_encode($data);
        //else include $template->load('userTemplate/weixin_func_Error/showMsg');
    }
}
//Web_output();